﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityModule;

namespace Sport
{
    public partial class Default : BasePage
    {
        static DataSet Get()
        {
            DataSet set = new DataSet();
            DataTable table = new DataTable("News");
            table.Columns.Add("ID");
            table.Columns.Add("Title");
            table.Columns.Add("Description");
            table.Columns.Add("Link");
            table.Columns.Add("udHour");
            table.Columns.Add("udImageTitle");
            table.Columns.Add("LinkCurrentPage");
            table.Columns.Add("udAuthor");
            table.Columns.Add("PageCount", typeof(int));
            List<New> newses = new NewsService().GetNews(_pageIndex, Common.PageSize);
            foreach (New newse in newses)
            {
                DataRow row = table.NewRow();
                row["ID"] = newse.ID.ToString();
                row["udHour"] = newse.udHour;
                row["udAuthor"] = newse.udAuthor;
                row["LinkCurrentPage"] = HttpContext.Current.Request.Url.AbsoluteUri.Replace("Default.aspx","") + "NewsDetail.aspx?ID=" + newse.ID;
                if (newse.UserID == null)
                {
                    if (newse.Body != null)
                        row["udImageTitle"] = newse.Body.GetInnerHtmlTag("a");
                }
                else
                {
                    row["udImageTitle"] = newse.User.Image;
                    row["LinkCurrentPage"] = "https://www.facebook.com/tan.xuan.353";

                }
                row["Title"] = newse.Tilte;
                if (newse.Body != null)
                    row["Description"] = newse.Body.RemoveTag("a").Replace("</br>", "");
                // row["PageCount"] = newses[0].PageCount;
                _pageCount = newses[0].PageCount;
                table.Rows.Add(row);
            }
            set.Tables.Add(table);
            return set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //RSSHelper.Start();
            if (!IsPostBack)
            {
                Session[Constant.UserID] = "100000804412689";
                //RSSHelper.Start();
                _pageIndex = 1;
                Common.PageSize = System.Configuration.ConfigurationSettings.AppSettings["PageSize"].AsInt();
                rptCustomers.DataSource = Get().Tables[0];
                rptCustomers.DataBind();
            }
        }

        static int _pageIndex = 1;
        static int _pageCount = 30;
        [WebMethod]
        public static string GetCustomers(int pageIndex)
        {
            _pageIndex++;
            return Get().GetXml();
        }
    }
}
